/**
 * 引用接口
 */
export abstract class IReference {
    /**
     * 清除引用
     */
    public abstract clear();
}
/**
 * 对象池
 */
export class ObjectPool {
    private static _instance: ObjectPool;
    /**
     * 单例
     */
    public static get instance(): ObjectPool {
        return this._instance = this._instance ? this._instance : new ObjectPool();
    }
    /**
     * 引用
     */
    private map: Map<string, IReference[]> = new Map<string, IReference[]>();
    /**
     * 获取
     * @param type 类型
     */
    get(type: typeof IReference) {
        let arr = this.map.get(type.name);
        if (!arr || arr.length == 0) {
            return null;
        } else {
            return arr.pop();
        }
    }
    /**
     * 添加
     * @param type 类型
     * @param obj 对象
     */
    put(type: typeof IReference, obj: IReference) {
        let arr = this.map.get(type.name);
        if (!arr) {
            arr = [];
            this.map.set(type.name, arr);
        }
        arr.push(obj);
    }
}